import { QUALITY_RANGE } from "./params/goodsParams";
import {
    updateGoodsValueByMinus,
    updateGoodsValueByAdd,
    isGoodsValueGreater,
    isGoodsValueLess,
} from './methods/qualityMethods'
import {updateExperationDateByDay} from "./methods/SellInMethod";

class Goods {
    type: string;
    sellIn: number;
    quality: number;
    constructor(type: string, SellIn: number, Quality: number) {
        this.type = type
        this.sellIn = SellIn
        this.quality = Quality
    }
    isOutOfRange() {
        if (this.quality > QUALITY_RANGE.MAX || this.quality < QUALITY_RANGE.MIN) {
            throw new RangeError('商品价值应在0-50之间')
        }
    }
    updateExperationDateByMinus() {
        this.sellIn = updateExperationDateByDay(this.sellIn)
    }
    // updateGoodsInfo() {}
    updateQualityByMinus() {
        if(isGoodsValueGreater(this.quality, QUALITY_RANGE.MIN)) {
            this.quality = updateGoodsValueByMinus(this.quality, 1)
        }
    }
    updateQualityByAdd() {
        if(isGoodsValueLess(this.quality, QUALITY_RANGE.MAX)) {
            this.quality = updateGoodsValueByAdd(this.quality, 1)
        }
    }
    getExpirationDate() {
        return this.sellIn
    }
    getGoodsValue() {
        return this.quality;
    }
}

export default Goods;